package org.geektimes.configuration.microprofile.config.sources;

import java.io.InputStream;
import java.net.URL;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Logger;

public class DefaultConfigSource extends MappedAbstractConfigSource {

	private final static String configFileLocation = "/application.properties";

	private final Logger logger = Logger.getLogger(this.getClass().getName());

	public DefaultConfigSource() {
		super(300, "Default-Source");
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	protected void prepareProperties(Map properties) throws Throwable {

		URL url = DefaultConfigSource.class.getResource(configFileLocation);
		if (url == null) {
			logger.info("The default config file can't be found in the classpath : " + configFileLocation);
			return;
		}
		try(InputStream inputStream =  url.openStream() ) {
			Properties pro = new Properties();
			pro.load(inputStream);
			properties.putAll(pro);
		}

	}

}
